#include <kuai/db/dbtool.hpp>

#include <kuai/mol/mol.hpp>


#ifndef _KUAI_MOL_DB_HPP_
#define _KUAI_MOL_DB_HPP_

namespace kuai {

	class InchiJob
		: public SequenceJob
	{
	public:
		InchiJob();

		DECLARE_JOB_CREATOR(InchiJob)

		virtual void pushParameter(const String& key, const String& data, std::ostream& output, std::ostream& error);
		virtual void doJob(std::ostream& output, std::ostream& error);

	private:
		size_t n, failed;
		String options;
	};

	class TinymolJob
		: public DatabaseJob
	{
	protected:
		boost::int64_t saveMol(Sqlite3DatabasePointer pdb, PhaseSpace& space, std::ostream& outlog);
	};

	class ImportSDFJob
		: public TinymolJob
	{
	public:
		DECLARE_JOB_CREATOR(ImportSDFJob);

	public:
		virtual void doJob(Sqlite3DatabasePointer pdb, std::ostream& out_log, std::ostream& err_log, StringMap& par);

	};


	class ImportRDFJob
		: public DatabaseJob
	{
	public:
		DECLARE_JOB_CREATOR(ImportRDFJob);

	public:
		virtual void doJob(Sqlite3DatabasePointer pdb, std::ostream& out_log, std::ostream& err_log, StringMap& par);
	};

	class QueryTinymolJob
		: public SequenceJob
	{
	public:
		DECLARE_JOB_CREATOR(QueryTinymolJob)

		QueryTinymolJob();
		virtual void pushParameter(const String& key, const String& data, std::ostream& output, std::ostream& error);
		virtual void doJob(std::ostream& output, std::ostream& error);
		

	private:
		void dumpMolRecord(Sqlite3Statement& sql, std::ostream& output);
		bool loadMol(Sqlite3Statement& sql, int icol, PhaseSpace& space);
		Sqlite3DatabasePointer pdb;
	};

}

#endif

